#include <iostream>
#include <fstream>
#include <vector>
#include "managerdao_file_impl.h"
#include "managerservice_impl.h"
#include "managerview_console_impl.h"
#include "manager.h"
#include "tools.h"

#include "department.h"
#include "employee.h"
#include "servicedao_file_impl.h"

#include "serviceview_console_impl.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

using namespace std;
using namespace MH;

//extern vector<Manager> v_manager;

int main()
{
	cout << "welcome to emis!" << endl;
	//Manager m;
	//cout << m.getId() << m.getName() << m.getPassword() << endl;
	//Tools t;
	//t.init_id();
	//cout << t.generator_MarId() << endl;
	//cout << t.generator_DeptId() << endl;
	//cout << t.generator_EmpId() << endl;
	/*
	int fd = open("data/managers.dat",O_CREAT|O_RDWR|O_TRUNC,0644);
	if(0 > fd)
	{
		perror("open");
		return -1;
	}
	Manager m1(1000,"tian","tian");
	write(fd,&m1,sizeof(Manager));
	Manager m2(1001,"zhi","zhi");
	write(fd,&m2,sizeof(Manager));
	Manager m3(1002,"lin","lin");
	write(fd,&m3,sizeof(Manager));
	Manager m4(1003,"xiao","xiao");
	write(fd,&m4,sizeof(Manager));
	close(fd);
	*/

	/*
	ManagerDaoFileImpl mana;
	mana.load();
	cout << v_manager[0].getName() << endl;
	cout << v_manager[1].getName() << endl;
	cout << v_manager[2].getName() << endl;
	cout << v_manager[3].getName() << endl;
	Manager m5(1006,"keke","keke");
	v_manager.push_back(m5);
	cout << v_manager[0].getName() << endl;
	cout << v_manager[1].getName() << endl;
	cout << v_manager[2].getName() << endl;
	cout << v_manager[3].getName() << endl;
	cout << v_manager[4].getName() << endl;	
	mana.save();
	*/
	/*
	ManagerServiceImpl mana;
	mana.listManager();
	Manager m1(2000,"AIAI","AIAI");
	mana.addManager(m1);
	mana.listManager();
	mana.deleteManager(2000);
	mana.listManager();
	*/
	//ManagerViewConsoleImpl mana;
	//mana.menu();
	//mana.list();
	//mana.del();
	//mana.add();
	//mana.list();

	/*
	Employee em(15015228,"shi",true,18);
	cout << em.getId() << endl;
	cout << em.getName() << endl;
	cout << em.getSex() << endl;
	cout << em.getAge() << endl;

	em.setName("liu");
	em.setSex(false);
	em.setAge(20);

	cout << em.getId() << endl;
	cout << em.getName() << endl;
	cout << em.getSex() << endl;
	cout << em.getAge() << endl;
	*/
	/*
	Department de(15,"yangfabu");

	de.addEmp();
	de.listEmp();
	de.addEmp();
	de.listEmp();
	de.deleteEmp(1012);
	de.listEmp();
	de.modifyEmp(1011);
	de.listEmp();
	*/

	/*
	ofstream output(SE_PATH,ios::out|ios::trunc);//write
	if(!output)
	{
		cerr << "out" << endl;
		exit(1);
	}

	int num = 10;
	Tools t;
	for(int i=0;i<10;i++)
	{
		Department de(t.generator_DeptId(),"shi");
		//cout << de.getId() << " " << de.getName() << " " << num << endl;
		output << de.getId() << " " << de.getName() << " " << num << endl;
		for(int j=0;j<10;j++)
		{
			Employee em(t.generator_EmpId(),"lin",false,18);
			//cout << em.getId() << " " << em.getName() << " " << (int)em.getSex()*100+em.getAge() << endl;
			output << em.getId() << " " << em.getName() << " " << (int)em.getSex()*100+em.getAge() << endl;
		}
	}
	*/

	
	//ServiceDaoFileImpl service;
	//vector<Department*> v_departmentp;
	//service.load(v_departmentp);
	/*
	while(!v_departmentp.empty())
	{
		Department* de = v_departmentp.back();
		cout << de->getId() << " " << de->getName() << " " << de->getV_employeep().size() << endl;
		v_departmentp.pop_back();
		while(!de->getV_employeep().empty())
		{
			Employee* em = de->getV_employeep().back();
			cout << em->getId() << " " << em->getName() << " " << em->getSex() << " " << em->getAge() << endl;
			de->getV_employeep().pop_back();
			delete em;
		}
		delete de;
	}
	*/
	//service.save(v_departmentp);
	ServiceViewConsoleImpl se;
	se.menu();

	cout << "----end----" << endl;
}
